package account.action;

import account.service.AccountService;
import com.opensymphony.xwork2.ActionSupport;
import generic.page.Page;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import util.ObtainOther;

/**
 * Created by chensui on 2016/12/17.
 */
public class AccountPageAction extends ActionSupport{
    private final static Log logger = LogFactory.getLog(AccountPageAction.class);


    private AccountService accountService;//通过Spring创建业务层对象  使用set方法依赖注入

    public AccountService getAccountService() {
        return accountService;
    }

    public void setAccountService(AccountService accountService) {
        this.accountService = accountService;
    }

    private Page page;

    public Page getPage() {
        return page;
    }

    public void setPage(Page page) {

        this.page = page;
    }

    private Integer pageSize;

    private Integer currentPage;

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    private String message;

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String listAccount()throws Exception{
        try{
            pageSize=ObtainOther.obtainPageSize("accountPageSize",pageSize);
            page = accountService.queryPage(pageSize, currentPage);//获取封装了分页信息和数据的pageBean
            return SUCCESS;
        }catch (Exception e){
            logger.error(message + ":/n" + e);
            message= ObtainOther.obtainMessage("loadAllAccountError");
            return ERROR;
        }

    }

}
